#!/usr/bin/env ruby
# coding: utf-8
# This is a port of the original 'spark' script by holman.
# You can find the original at https://github.com/holman/spark

ticks = %w(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
numbers = STDIN.each_line.map { |n| n.split(' ') }.flatten.map { |n| n.to_f }
if numbers.length == 0
  puts "Usage: <source> | spark"
else
  min = numbers.min
  numbers.map! { |n| n - min }
  max = numbers.max
  if max == 0
    numbers.each { print '▆' }
  else
    sum = numbers.reduce { |a, b| a + b }
    avg = sum / numbers.length
    numbers.each do |n|
      d = (n / avg) / (max / avg)
      i = (d * (ticks.length - 1)).round
      print(ticks[i])
    end
  end
end

puts
